<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>面向对象之一 | 金旭的个人博客</title>
  <meta name="description" content="面向对象的三个方面 Java类及类的成员：属性、方法、构造器、代码块、内部类 面向对象的三大特征：封装型、集成性、多态（抽象性） 其他关键字：this、super、static、final、abstract、interface、package、import等  面向对象和面向过程二者都是一种思想，面向对象是相对于面向过程而言的，面向过程强调的是功能行为以函数为最小单位，考虑怎么做。面向对象，将功能">
<meta property="og:type" content="article">
<meta property="og:title" content="面向对象之一">
<meta property="og:url" content="http://sunjinxu99.gitee.io/blog/2020/04/02/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E4%B8%80/index.html">
<meta property="og:site_name" content="金旭的个人博客">
<meta property="og:description" content="面向对象的三个方面 Java类及类的成员：属性、方法、构造器、代码块、内部类 面向对象的三大特征：封装型、集成性、多态（抽象性） 其他关键字：this、super、static、final、abstract、interface、package、import等  面向对象和面向过程二者都是一种思想，面向对象是相对于面向过程而言的，面向过程强调的是功能行为以函数为最小单位，考虑怎么做。面向对象，将功能">
<meta property="og:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200408091048.png">
<meta property="og:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200408100830.png">
<meta property="og:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200408100909.png">
<meta property="article:published_time" content="2020-04-02T04:33:05.248Z">
<meta property="article:modified_time" content="2020-04-14T11:18:56.297Z">
<meta property="article:author" content="金旭">
<meta property="article:tag" content="面向对象">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/sunjinxu99/image/raw/master/img/20200408091048.png">
  <!-- Canonical links -->
  <link rel="canonical" href="http://sunjinxu99.gitee.io/blog/2020/04/02/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E4%B8%80/index.html">
  
    <link rel="alternate" href="/atom.xml" title="金旭的个人博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.2.0"></head>


<body class="main-center theme-blue# 主题颜色 theme-black theme-blue theme-green theme-purple" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.png" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">小马</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md"></h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> </small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="Search" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="Type something..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">Home</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">Archives</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">Categories</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">Tags</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">About</span>
          </a>
        </li>
        
      </ul>
      
    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">Board</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>朝闻道夕死可矣</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">Categories</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/JavaSE/">JavaSE</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/LeetCode/">LeetCode</a><span class="category-list-count">3</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/LeetCode/%E7%AE%97%E6%B3%95/">算法</a><span class="category-list-count">3</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%9D%82%E8%AE%B0/">杂记</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/IO%E6%B5%81/" style="font-size: 13px;">IO流</a> <a href="/blog/tags/OSI%E5%8F%82%E8%80%83%E6%A8%A1%E5%9E%8B/" style="font-size: 13px;">OSI参考模型</a> <a href="/blog/tags/TCP-IP%E5%8F%82%E8%80%83%E6%A8%A1%E5%9E%8B/" style="font-size: 13px;">TCP/IP参考模型</a> <a href="/blog/tags/ftp%E5%8D%8F%E8%AE%AE/" style="font-size: 13px;">ftp协议</a> <a href="/blog/tags/http/" style="font-size: 13px;">http</a> <a href="/blog/tags/leetcode/" style="font-size: 13px;">leetcode</a> <a href="/blog/tags/%E4%BA%8C%E5%88%86%E6%95%B0%E7%BB%84/" style="font-size: 13px;">二分数组</a> <a href="/blog/tags/%E4%BA%8C%E5%8F%89%E6%A0%91/" style="font-size: 13px;">二叉树</a> <a href="/blog/tags/%E5%85%A8%E6%8E%92%E5%88%97/" style="font-size: 13px;">全排列</a> <a href="/blog/tags/%E5%8F%8C%E6%8C%87%E9%92%88/" style="font-size: 13.33px;">双指针</a> <a href="/blog/tags/%E5%8F%8D%E5%B0%84/" style="font-size: 13px;">反射</a> <a href="/blog/tags/%E5%93%88%E5%B8%8C%E8%A1%A8/" style="font-size: 13.67px;">哈希表</a> <a href="/blog/tags/%E5%9B%9E%E6%BA%AF%E6%B3%95/" style="font-size: 13px;">回溯法</a> <a href="/blog/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" style="font-size: 13px;">多线程</a> <a href="/blog/tags/%E5%AD%97%E7%AC%A6%E4%B8%B2/" style="font-size: 13px;">字符串</a> <a href="/blog/tags/%E6%8E%92%E5%BA%8F/" style="font-size: 13.33px;">排序</a> <a href="/blog/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" style="font-size: 14px;">数据结构</a> <a href="/blog/tags/%E6%9D%82%E8%AE%B0/" style="font-size: 13px;">杂记</a> <a href="/blog/tags/%E6%A0%88/" style="font-size: 13px;">栈</a> <a href="/blog/tags/%E6%B3%9B%E5%9E%8B/" style="font-size: 13px;">泛型</a> <a href="/blog/tags/%E7%AE%97%E6%B3%95/" style="font-size: 13.33px;">算法</a> <a href="/blog/tags/%E8%8F%B2%E6%B3%A2%E9%82%A3%E5%88%87%E6%95%B0%E5%88%97/" style="font-size: 13.33px;">菲波那切数列</a> <a href="/blog/tags/%E9%80%92%E5%BD%92/" style="font-size: 13px;">递归</a> <a href="/blog/tags/%E9%93%BE%E8%A1%A8/" style="font-size: 13.33px;">链表</a> <a href="/blog/tags/%E9%98%9F%E5%88%97/" style="font-size: 13px;">队列</a> <a href="/blog/tags/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/" style="font-size: 13px;">面向对象</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">Archive</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/07/">July 2021</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/07/">July 2020</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/05/">May 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/04/">April 2020</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/03/">March 2020</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E9%95%9C%E5%83%8F/" class="title">二叉树的镜像</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T12:34:40.165Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%8E%92%E5%BA%8F%E7%9A%84%E9%93%BE%E8%A1%A8/" class="title">合并两个排序的链表</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T09:26:07.612Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E4%BB%8E%E5%B0%BE%E5%88%B0%E5%A4%B4%E6%89%93%E5%8D%B0%E9%93%BE%E8%A1%A8/" class="title">从尾到头打印链表</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T08:02:42.111Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E6%9B%BF%E6%8D%A2%E7%A9%BA%E6%A0%BC/" class="title">替换空格</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T06:28:22.026Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/blog/2021/07/14/%E6%97%8B%E8%BD%AC%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%B0%8F%E6%95%B0%E5%AD%97/" class="title">旋转数组的最小数字</a>
              </p>
              <p class="item-date">
                <time datetime="2021-07-14T06:12:09.184Z" itemprop="datePublished">2021-07-14</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<main class="main" role="main">
  <div class="content">
  <article id="post-面向对象之一" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      面向对象之一
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2020/04/02/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E4%B8%80/" class="article-date">
	  <time datetime="2020-04-02T04:33:05.248Z" itemprop="datePublished">2020-04-02</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/JavaSE/">JavaSE</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/" rel="tag">面向对象</a>
  </span>


        

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2020/04/02/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E4%B8%80/#comments" class="article-comment-link">Comments</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h3 id="面向对象的三个方面"><a href="#面向对象的三个方面" class="headerlink" title="面向对象的三个方面"></a>面向对象的三个方面</h3><ul>
<li>Java类及类的成员：属性、方法、构造器、代码块、内部类</li>
<li>面向对象的三大特征：封装型、集成性、多态（抽象性）</li>
<li>其他关键字：this、super、static、final、abstract、interface、package、import等</li>
</ul>
<h3 id="面向对象和面向过程"><a href="#面向对象和面向过程" class="headerlink" title="面向对象和面向过程"></a>面向对象和面向过程</h3><p>二者都是一种思想，面向对象是相对于面向过程而言的，面向过程强调的是功能行为以函数为最小单位，考虑怎么做。面向对象，将功能封装进对象，强调具备了功能的对象，以类、对象为最小单位，考虑谁来做。</p>
<h3 id="面向对象的两要素：类和对象"><a href="#面向对象的两要素：类和对象" class="headerlink" title="面向对象的两要素：类和对象"></a>面向对象的两要素：类和对象</h3><ul>
<li>类是对一类事物的描述，是抽象的，概念性的定义</li>
<li>对象是实际存在该类事物的个体，因此也称实例<br>面向对象的重点是设计类，设计类就是设计类的成员（属性、方法）。属性（成员变量、filed），方法（成员方法、函数、method）<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> calss <span class="title">PersonTest</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line">        <span class="comment">// 创建对象实例</span></span><br><span class="line">        Person p1 = <span class="keyword">new</span> Person();</span><br><span class="line">        <span class="comment">// 调用属性</span></span><br><span class="line">        p1.name = <span class="string">"Tom"</span>;</span><br><span class="line">        p1.isMale = <span class="keyword">true</span>;</span><br><span class="line">        System.out.println(p1.name);</span><br><span class="line">        <span class="comment">// 调用方法</span></span><br><span class="line">        p1.eat();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Person</span>()</span>&#123;</span><br><span class="line">    <span class="comment">// 属性</span></span><br><span class="line">    String name;</span><br><span class="line">    <span class="keyword">int</span> age;</span><br><span class="line">    <span class="keyword">boolean</span> isMale;</span><br><span class="line">    <span class="comment">// 方法</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">sleep</span><span class="params">()</span></span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"人可以睡觉"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">eat</span><span class="params">()</span></span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"人可以吃饭);</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#125;</span></span><br></pre></td></tr></table></figure>
<h3 id="类的实例化"><a href="#类的实例化" class="headerlink" title="类的实例化"></a>类的实例化</h3>如果创建了一个类的多个对象，则每个对象都独立拥有一套类的属性</li>
</ul>
<ol>
<li>创建类，设计成员</li>
<li>创建类的方法</li>
<li>通过“对象.属性”或者“对象.方法”调用功能</li>
</ol>
<h3 id="属性与局部变量"><a href="#属性与局部变量" class="headerlink" title="属性与局部变量"></a>属性与局部变量</h3><ol>
<li>相同点:<ul>
<li>定义格式：数据类型 变量名 = 变量值</li>
<li>先声明 后使用</li>
<li>变量都有其使用域</li>
</ul>
</li>
<li>不同点：<ul>
<li>属性声明在类的{}内，局部变量声明在方法、方法形参、代码块、构造器内的变量。</li>
<li>属性：可以在声明属性时，指明权限，使用权限修饰符（private、public、缺省、protected）。局部变量不能使用权限修饰符。</li>
<li>属性：类的属性根据其类型都有其初始化值。局部变量没有初始化值，一定要显式赋值。形参在调用时赋值即可。</li>
<li>在内存中加载的位置。属性在堆空间中（非static），局部变量加载在栈空间中。</li>
</ul>
</li>
</ol>
<h3 id="类中方法的声明和使用"><a href="#类中方法的声明和使用" class="headerlink" title="类中方法的声明和使用"></a>类中方法的声明和使用</h3><p>方法：描述类应该具有的功能</p>
<ul>
<li>方法的声明：权限修饰符 返回值类型 方法名（形参列表）{方法体}(暂未考虑abstrct、static、final等）<h3 id="return的使用"><a href="#return的使用" class="headerlink" title="return的使用"></a>return的使用</h3></li>
<li>使用范围：方法体中</li>
<li>作用：结束方法、返回所需的数据</li>
<li>return后，不要有执行语句</li>
</ul>
<h3 id="匿名对象的使用"><a href="#匿名对象的使用" class="headerlink" title="匿名对象的使用"></a>匿名对象的使用</h3><p> 新建的对象并没有显式的赋给变量，匿名对象只能调用一次<br> <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> Person().name;</span><br></pre></td></tr></table></figure></p>
<h3 id="方法的重载"><a href="#方法的重载" class="headerlink" title="方法的重载"></a>方法的重载</h3><p>在同一个类中，允许存在一个以上的同名方法，只要它们的参数个数或者参数的类型不同即可</p>
<ul>
<li>两同一不同：同一个类，相同方法名，参数列表不同（个数、类型）<h3 id="可变个数的形参方法"><a href="#可变个数的形参方法" class="headerlink" title="可变个数的形参方法"></a>可变个数的形参方法</h3></li>
<li>可变个数形参的形式：数据类型 … 变量名</li>
<li>调用时可以的参数个数为：0，1，2。。。</li>
<li>可以构成重载</li>
<li>形参类型与其相同类型的数组不构成重载</li>
<li>可变个数形参方法必须声明在末尾<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MethodArgsTest</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line">        MethodArgsTest test = <span class="keyword">new</span> MethodTest();</span><br><span class="line">        test.show(<span class="number">11</span>);</span><br><span class="line">        test.show(<span class="string">"hello"</span>,<span class="string">"world"</span>);</span><br><span class="line">    &#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">show</span><span class="params">(<span class="keyword">int</span> i)</span></span>&#123;</span><br><span class="line">    System.out.print(i);</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">show</span><span class="params">(String ... strs)</span></span>&#123;</span><br><span class="line">    System.out.print(strs);</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="方法参数的值传递机制"><a href="#方法参数的值传递机制" class="headerlink" title="方法参数的值传递机制"></a>方法参数的值传递机制</h3>变量的赋值：如果变量是基本数据类型，此时赋值的是变量保持的数据值。如果变量是引用数据类型，此时保存的是地址值。交换引用数据类型的值，需要引用中间数据类型参与。也就是说要访问对象的值需要创建中间的对象。</li>
<li>如果参数是基本数据类型，此时实参赋给形参真是存储的数据值</li>
<li>如果参数是引用数据类型，此时实参赋给的是实参存储的地址值</li>
</ul>
<h3 id="面向对象的特征：封装与隐藏"><a href="#面向对象的特征：封装与隐藏" class="headerlink" title="面向对象的特征：封装与隐藏"></a>面向对象的特征：封装与隐藏</h3><p>当我们创建一个对象之后，我们可以对属性进行赋值。赋值操作要受到属性类型和存储范围的制约。但是，在实际的问题中，我们往往需要给属性赋值加入其它额外条件，这个不能在条件声明时体现，我们只能通过方法进行限制。这体现了属性的封装性。</p>
<p>例如将属性私有化，但是提供公共的方法set和get来设置和获取属性的值</p>
<h3 id="四种权限修饰符"><a href="#四种权限修饰符" class="headerlink" title="四种权限修饰符"></a>四种权限修饰符</h3><p>private、缺省、protected、public<br><img src="https://gitee.com/sunjinxu99/image/raw/master/img/20200408091048.png" alt=""></p>
<h3 id="构造器的使用"><a href="#构造器的使用" class="headerlink" title="构造器的使用"></a>构造器的使用</h3><ul>
<li>构造器的作用：创建对象（Person p = new Person（），Person（）就是构造器）;初始化属性值</li>
<li>构造器的格式 权限修饰符 类名（形参列表）{}，一个类的多个构造器彼此构成重载。</li>
</ul>
<h3 id="属性赋值的先后顺序"><a href="#属性赋值的先后顺序" class="headerlink" title="属性赋值的先后顺序"></a>属性赋值的先后顺序</h3><p>默认初始化、显式初始化、构造器赋值、通过对象方法或者对象属性赋值</p>
<h3 id="javabean"><a href="#javabean" class="headerlink" title="javabean"></a>javabean</h3><p><a href="https://www.zhihu.com/question/19773379" target="_blank" rel="noopener">javabean的由来</a></p>
<h3 id="UML类图"><a href="#UML类图" class="headerlink" title="UML类图"></a>UML类图</h3><p><img src="https://gitee.com/sunjinxu99/image/raw/master/img/20200408100830.png" alt=""><br><img src="https://gitee.com/sunjinxu99/image/raw/master/img/20200408100909.png" alt=""><br><a href="https://www.jianshu.com/p/57620b762160" target="_blank" rel="noopener">UML的详细介绍</a></p>
<h3 id="this关键字"><a href="#this关键字" class="headerlink" title="this关键字"></a>this关键字</h3><p>用this来指代当前对象。用来调用当前对象的属性、方法、构造器</p>
<ul>
<li>调用构造器 </li>
</ul>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://sunjinxu99.gitee.io/blog/2020/04/02/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E4%B8%80/" title="面向对象之一" target="_blank" rel="external">http://sunjinxu99.gitee.io/blog/2020/04/02/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E4%B8%80/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="" target="_blank"><span class="text-dark">小马</span><small class="ml-1x"></small></a></h3>
        <div></div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2020/04/12/IO%E6%B5%81/" title="IO流"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;Newer</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2020/03/31/javaSE_01/" title="JavaSE_01"><span>Older&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
  </ul>
  
  
  
  <div class="bar-right">
    
  </div>
  </div>
</nav>
  


</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
    <div class="copyright">
    	
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: 'Posts',
            PAGES: 'Pages',
            CATEGORIES: 'Categories',
            TAGS: 'Tags',
            UNTITLED: '(Untitled)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   




   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>